<template>
  <div>
      <div style="margin: 40px;color: red;">
          <div>提示：1.额定人数为教学班允许最多上课人数</div>
          <div>&emsp;&emsp;&emsp;2.最大预选人数为教学班允许选课人数</div>
      </div>
    <div class="assessment-container">
      <div class="table-container">
        <el-table
          :data="tableData"
          border
          class="xpaas-table-class"
          row-class-name="xpaas-row-class"
          cell-class-name="xpaas-cell-class"
          header-row-class-name="xpaas-header-row-class"
          header-cell-class-name="xpaas-header-cell-class"
          style="height: 580px; overflow-y: auto"
        >
          <el-table-column prop="kcbh" label="课程编号" align="center">
          </el-table-column>
          <el-table-column prop="courseName" label="课程名称" align="center">
          </el-table-column>
          <el-table-column
            prop="reserveNum"
            label="额定人数"
            width="130"
            align="center"
          >
          <template slot-scope="scope">
          <el-input
              v-model="scope.row.reserveNum"
              size="mini"
              style="width: 85px"
            ></el-input>人
          </template>
          </el-table-column>
          <el-table-column
            prop="maxNum"
            label="最大预选人数"
            width="130"
            align="center"
          >
          <template slot-scope="scope">
          <el-input
              v-model="scope.row.maxNum"
              size="mini"
              style="width: 85px"
            ></el-input>人
          </template>
          </el-table-column>
          <el-table-column
            prop="xkbs"
            label="新开班数"
            width="130"
            align="center"
          >
          <template slot-scope="scope">
          <el-input
              v-model="scope.row.xkbs"
              size="mini"
              style="width: 85px"
            ></el-input>
          </template>
          </el-table-column>
          <el-table-column prop="fl" label="分类" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.fl"
                  size="mini"
                  style="width: 85px"
                ></el-input>
                  <!-- <SelectItem
                    :name="'分类'"
                    :value="scope.row.fl"
                    @change="
                    (e) => {
                        scope.row.fl = e;
                    }
                    "
                    :xqList="typeList"
                ></SelectItem> -->
              </template>
          </el-table-column>
          <el-table-column
            prop="ykbs"
            label="已开班数"
            width="130"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="classRoom"
            label="课程承担教研室"
            align="center"
          >
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="btn-caozuo">
      <div class="button-style" style="border-color: #F3B815; background-color: #FFF6EF; margin-right: 15px;" @click="lastStep">
        <span style="color: #F3B815;">上一步</span>
      </div>
      <div class="button-style" style="border-color: #F3B815; background-color: #FFF6EF; margin-right: 15px;" @click="submitExportData">
        <span style="color: #F3B815;">完&emsp;成</span>
      </div>
      <div class="button-style" style="border-color: #F05943; background-color: #FFEEF3; margin-right: 15px;" @click="cancelStep">
        <span style="color: #F05943;">取&emsp;消</span>
      </div>

    </div>
  </div>
</template>

<script>
import {xxkkkgl_JH_course, xxkkkgl_JH_Course_add} from "@/api/trainingManagement/place.js";
import ButtonItem from "@/components/ButtonItem.vue";
export default {
  components: {
    ButtonItem,
  },
  data() {
    return {
      tableData: [],
      typeList: [{label: "全部",value: "全部"}],
      xueqi: "", //学期
      list: [], //查询参数
    };
  },
  created() {},
  mounted() {
    this.list = this.$route.query.list;
    this.xueqi = this.list[0].xueqi
    this.queryPlaceInfo();
  },
  methods: {
    cancelStep() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.push("/admin/elective/startClassManagement");
    },
    lastStep() {
      this.$router.push("/admin/elective/addElectiveCourses");
    },
     // 从培养计划添加选修课 -提交
    async submitExportData() {
      var params = [];
      var xq = this.xueqi;
      for (let index = 0; index < this.tableData.length; index++) {
        const item = this.tableData[index]
        if (item.reserveNum === '') {
          this.$message.warning('第' + (index + 1) + '行额定人数未填写！')
          return
        }
        if (item.maxNum === '') {
          this.$message.warning('第' + (index + 1) + '行最大预选人数未填写！')
          return
        }
        if (item.xkbs === '') {
          this.$message.warning('第' + (index + 1) + '行新开班数未填写！')
          return
        }
        if (item.fl === '') {
          this.$message.warning('第' + (index + 1) + '行分类未填写！')
          return
        }
        var par = {
          "kcbh": item.kcbh,
          "courseName": item.courseName,
          "reserveNum": item.reserveNum,
          "maxNum": item.maxNum,
          "fl": item.fl,
          "xkbs": item.xkbs,
          "nj": item.nj,
          "xueqi": xq
        }
        params.push(par)
      }
      const res = await xxkkkgl_JH_Course_add(params);
      if (res.data.code === 200) {
        this.$message.success("添加成功!");
        this.$router.push("/admin/elective/startClassManagement");
      }
    },
    async queryPlaceInfo() {
      const res = await xxkkkgl_JH_course(this.list);
      if (res.data.code === 200) {
        this.tableData = res.data.data;
        this.tableData.forEach(item => {
          item.xkbs = ''
          item.ykbs = item.ykbs === -1 ? 0 : item.ykbs
        })
      }
    },
  },
};
</script>
<style lang="less" scoped>
@import "../../../../styles/text.less";

/deep/ .szjky .el-dialog__body {
  height: 432px;
}
.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.message-container {
  > div {
    display: inline-block;
    &:nth-child(1) {
      padding-left: 111px;
      font-size: 20px;
      color: rgba(0, 76, 167, 1);
      font-weight: bold;
      vertical-align: top;
    }
    &:nth-child(2) {
    }
  }
}
</style>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";

.wrapper-container {
  width: 1711px;
  margin: 0 auto;
}

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  flex-wrap: wrap;
  .search-container-item {
    width: 12%;
    margin-right: 0px;
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      margin-bottom: 20px;
      align-items: center;
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}
.bottom-block {
  // display: flex;
  flex-direction: row;
  justify-content: space-between !important;
  .export-button {
    width: 127px;
    height: 27px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      margin-left: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
  }
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}

.btn-caozuo {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 800px;
  margin: 0 auto;
  padding-top: 50px;
}

.assessment-container {
  width: calc(100% - 20px);
  .table-container {
     width: 100%;
  }
}
@fontFamily:"Microsoft YaHei";
.xpaas-table-class {
  border: 1px solid #004ca7;
  border-radius: 9px;
  ::v-deep div.el-table__header-wrapper {
    table.el-table__header {
      thead {
        tr.xpaas-header-row-class {
          padding: 0;
          height: 60px;
          background-color: #edf2f9;
          font-size: 16px;
          font-family: @fontFamily;
          font-weight: bold;
          line-height: 20px;
          color: #004ca7;
          th.xpaas-header-cell-class {
            font-weight: bold;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
  ::v-deep div.el-table__body-wrapper {
    table.el-table__body {
      tbody {
        tr.xpaas-row-class {
          td.xpaas-header-cell-class {
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
          td.xpaas-cell-class {
            height: 60px;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            div.cell {
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
}
.button-style {
  float: left;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  width: auto;
  height: 28px;
  line-height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-wrap: nowrap;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  box-sizing: border-box;
  > img {
    width: 16px;
    height: 16px;
    margin-right: 5px;
  }
  > span {
    font-size: 14px;
    color: #51aef6;
  }
}
</style>
